package com.civil.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.civil.mapper.CivilMapper;
import com.civil.mapper.UserInfoMapper;
import com.civil.response.DateUtil;
import com.civil.service.CivilService;



@Service
@Transactional
public class CivilServiceImpl implements CivilService{

	@Autowired
	CivilMapper civilMapper;
	
	@Autowired
	UserInfoMapper userInfoMapper;
	

	@Override
	public void insert(Map<String, Object> params) {
		
		
		Map<String, Object> result = userInfoMapper.findDetailById(params.get("uid").toString());
		String str = "";
		if(result != null){
				try {
					if(result.get("sex").toString().equals("男")){
						str = DateUtil.dateAddYear(params.get("cssj").toString(),60);
					}else{
						str = DateUtil.dateAddYear(params.get("cssj").toString(),55);
					}
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		String gzdj = params.get("gzdj").toString();
		if(gzdj.equals("二级科员")||gzdj.equals("一级科员")){
			params.put("zws", params.get("bz"));
		}
		if(gzdj.equals("四级主任科员")||gzdj.equals("三级主任科员")
				||gzdj.equals("二级主任科员")||gzdj.equals("一级主任科员")){
			params.put("zws", (Integer.valueOf(params.get("bz").toString())*0.6)/2);
		}
		if(gzdj.equals("四级调研员")||gzdj.equals("三级调研员")){
			params.put("zws", (Integer.valueOf(params.get("bz").toString())*0.1));
		}
		if(gzdj.equals("二级调研员")||gzdj.equals("一级调研员")){
			params.put("zws", (Integer.valueOf(params.get("bz").toString())*0.02));
		}
		params.put("txsj", str);	
		civilMapper.insert(params);
	}

	@Override
	public Map<String, Object> findList(Map<String, Object> params) {
		params.put("page",
				(Integer.valueOf(params.get("page").toString()) - 1) * Integer.valueOf(params.get("limit").toString()));
		List<Map<String, Object>> list = civilMapper.findList(params);
		int count = civilMapper.findCount(params);
		params = new HashMap<String, Object>();
		params.put("list", list);
		params.put("count", count);
		return params;
	}


	@Override
	public Map<String, Object> findDetailById(String id) {
		return civilMapper.findDetailById(id);
	}


	@Override
	public void updateById(Map<String, Object> params) {
		civilMapper.updateById(params);
	}


	@Override
	public void deleteById(String id) {
		civilMapper.deleteById(id);
	}


	@Override
	public List<Map<String, Object>> findListUser() {
		return civilMapper.findListUser();
	}

	
}
